package com.etop.jansing.entities;

import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by jansing on 2015/10/25.
 */
@Entity
@Table(name = "resource")
public class Resource extends BaseEntity {
    /**
     * 该属性唯一
     */
    @Column(name = "name")
    private String name;

    /**
     * 资源的中文名，<br/>
     */
    @Column(name = "cnName")
    private String cnName;
    /**
     * 在页面显示时的排列顺序，<br/>
     * 值越小，越靠前。
     */
    @Column(name = "orderId")
    private Integer orderId;
    /**
     * 如果是叶子资源，则有对应的url以进入其管理页面
     */
    @Column(name = "url")
    private String url;
    /**
     * 父级资源
     */
    @ManyToOne(targetEntity = Resource.class, fetch = FetchType.LAZY)
    @JoinColumn(name = "pid")
    private Resource parent;

    /**
     * 子资源
     */
    @OneToMany(mappedBy = "parent", fetch = FetchType.LAZY)
    @Fetch(FetchMode.SUBSELECT)
    private List<Resource> subList = new ArrayList<>();

    @OneToMany(mappedBy = "resource", fetch = FetchType.LAZY)
    @Fetch(FetchMode.SUBSELECT)
    private List<ResourcePermission> resourcePermissionList = new ArrayList<>();

    public Resource() {
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getCnName() {
        return cnName;
    }

    public void setCnName(String cnName) {
        this.cnName = cnName;
    }

    public Integer getOrderId() {
        return orderId;
    }

    public void setOrderId(Integer orderId) {
        this.orderId = orderId;
    }

    public Resource getParent() {
        return parent;
    }

    public void setParent(Resource parent) {
        this.parent = parent;
    }

    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }

    public List<ResourcePermission> getResourcePermissionList() {
        return resourcePermissionList;
    }

    public void setResourcePermissionList(List<ResourcePermission> resourcePermissionList) {
        this.resourcePermissionList = resourcePermissionList;
    }

    public List<Resource> getSubList() {
        return subList;
    }

    public void setSubList(List<Resource> subList) {
        this.subList = subList;
    }

}
